package com.info.zhiduoduo.core.formbean;

import com.info.zhiduoduo.common.utils.NumberUtil;
import com.info.zhiduoduo.repository.entity.company.CompanyProject;
import com.info.zhiduoduo.repository.entity.entrustmentproject.EntrustmentProjectItem;

import java.math.BigDecimal;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class CalcProjectChargesFormBean {

	/** 计算的项目金额类型, 取值于 {@link com.info.zhiduoduo.common.constants.project.CalcAmountType} */
	private int calcAmountType;
	private int userid;
	private int compid;
	private int projectid;
	/** 委托项目、创客团项目的父项目id */
	private int parentProjectId;
	private int projectType;
	private int invoicetype;
	private BigDecimal amount;

	/**
	 * @param project
	 * @param calcAmountType 计算的项目金额类型, 取值于 {@link com.info.zhiduoduo.common.constants.project.CalcAmountType}
	 * @return
	 */
	public static CalcProjectChargesFormBean of(CompanyProject project, int calcAmountType) {
		CalcProjectChargesFormBean bean = new CalcProjectChargesFormBean();
		return bean.setCalcAmountType(calcAmountType)
				.setUserid(project.getUserid())
				.setCompid(project.getCompid())
				.setProjectid(project.getProjectid())
				.setProjectType(project.getType())
				.setAmount(project.getProjectamount())
				.setInvoicetype(project.getInvoicetype());
	}

	/**
	 * @param item
	 * @param calcAmountType 计算的项目金额类型, 取值于 {@link com.info.zhiduoduo.common.constants.project.CalcAmountType}
	 * @return
	 */
	public static CalcProjectChargesFormBean of(EntrustmentProjectItem item, int calcAmountType) {
		CalcProjectChargesFormBean bean = new CalcProjectChargesFormBean();
		return bean.setCalcAmountType(calcAmountType)
				.setUserid(NumberUtil.safeInt(item.getEntrusteeId()))
				.setCompid(NumberUtil.safeInt(item.getCompid()))
				.setProjectid(NumberUtil.safeInt(item.getId()))
				.setParentProjectId(NumberUtil.safeInt(item.getImportId()))
				.setProjectType(NumberUtil.safeInt(item.getProjectType()))
				.setAmount(item.getProjectAmount())
				.setInvoicetype(NumberUtil.safeInt(item.getInvoiceType()));
	}
}
